package com.zx.article.manager.service.impl;

import javax.servlet.http.HttpServletRequest;

import com.zx.article.manager.dao.IManagerDao;
import com.zx.article.manager.dao.impl.ManagerDaoImpl;
import com.zx.article.manager.model.ManagerModel;
import com.zx.article.manager.service.IManagerService;

public class ManagerServiceImpl implements IManagerService {

	private IManagerDao managerDao = new ManagerDaoImpl();

	@Override
	public String reg(ManagerModel managerModel) {
		ManagerModel queryModel = managerDao.queryModel(managerModel.getAccount());
		if (queryModel == null) {
			return managerDao.insertModel(managerModel);
		} else {
			return "repeat";
		}
	}

	@Override
	public String login(ManagerModel managerModel, HttpServletRequest request) {
		ManagerModel queryModel = managerDao.queryModel(managerModel);
		if (queryModel == null) {
			return "fail";
		} else {
			request.getSession().setAttribute("user", queryModel);
			return "success";
		}
	}

	@Override
	public String updata(ManagerModel managerModel, HttpServletRequest request) {
		if ("1".equals(managerDao.updata(managerModel))) {
			ManagerModel queryModel = managerDao.queryModel(managerModel.getAccount());
			request.getSession().setAttribute("user", queryModel);
			return "success";
		}
		return "fail";
	}

}
